<template>
  <div>
    <h2>精品推荐</h2>
    <div class="list-top"
    @click="clickItem(item.id)"
     v-for="item in items" :key="item.id">
      <img v-lazy="item.pic" alt="" />
      <div class="list-div1">
        <h2>{{ item.name }}</h2>
        <p class="list-p">
          <!-- 三目嵌套三目判断描述内容超过10的时候显示点点点 -->
          {{
            item.characteristic
              ? item.characteristic.length < 10
                ? item.characteristic.length
                : item.characteristic.substr(0, 10) + "...."
              : "暂无商品描述"
          }}
        </p>
        <div class="div">
          <p class="p">￥{{ item.minPrice }}</p>
          <van-icon
            @click.stop="clickAddCart(item.id,item)"
            name="gouwuche"
            class-prefix="icon"
            size="24"
            color="pink"
          ></van-icon>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    items: {
      type: Array,
      requird: true
    }
  },
  methods: {
    clickAddCart (id, item) {
      // 点击加入购物车图标
      this.$emit('clickAddIcon', { id, item })
    },
    clickItem (id) {
      // 点击商品传入id
      this.$emit('clickItem', id)
    }
  }
}
</script>

<style lang="scss" scoped>
h2 {
  font-size: 18px;
  text-align: center;
}
.list-top {
  background: rgb(182, 21, 48);
  width: 9rem;
  display: flex;
  justify-content: flex-start;
  padding-bottom: 50px;
  margin: 10px;
  border-radius: 5px;
  overflow: hidden;
  img {
    width: 140px;
    height: 140px;
    margin-top: 10px;
    margin-left: 5px;
  }
  h2 {
    margin-top: 0;
    font-size: 18px;
    margin-top: 20px;
  }
  .list-p {
    font-size: 16px;
    color: rgb(57, 145, 145);
    font-weight: 400;
    text-align: center;
  }
  .div {
    width: 140px;
    display: flex;
    justify-content: space-between;
    .icon {
      margin-top: 16px;
    }
  }
  .list-div1 {
    margin-left: 10px;
  }
  .p {
    font-size: 16px;
    font-weight: 800;
    margin-left: 20px;
  }
}
</style>
